
 var whichAward = function (deg) {
     console.log('角度：' + deg);
     if (deg >= 260 && deg < 280) {
         window.localStorage.setItem('prize', 'no4')
         $('.mask').fadeIn("slow")
         $('.mask-mony').attr('src', './imgs/no4.png').on('tap', function () {
            //  alert('这是要跳转页面的操作')
            window.location.href = 'https://crmminisite.verystar.cn/wx_service/self_extract?event_key=42ed0eee8643e9218cdd19c98e149540'
            
            //  window.localStorage.removeItem('prize')             
         })
         console.log('4等奖');
         return 'four'

     } else if (deg >= 210 && deg <= 230) {
         window.localStorage.setItem('prize', 'no2')
         $('.mask').fadeIn("slow")
         $('.mask-mony').attr('src', './imgs/no2.png').on('tap', function () {
            //  alert('这是要跳转页面的操作')
            window.location.href = 'https://crmminisite.verystar.cn/wx_service/self_extract?event_key=9f74a18075b6e44fd73dbf05d503fa3f'
            
            //  window.localStorage.removeItem('prize')
         })

         return 'tow'
     } else if (deg >= 310 && deg <= 330) {
         window.localStorage.setItem('prize', 'no3')
         $('.mask').fadeIn("slow")
         $('.mask-mony').attr('src', './imgs/no3.png').on('tap', function () {
            //  alert('这是要跳转页面的操作')
            window.location.href = 'https://crmminisite.verystar.cn/wx_service/self_extract?event_key=0022a3e4eec8ff9c15a6eaa19a7f0f86'
            
            //  window.localStorage.removeItem('prize')
         })

         return 'three'
     } else if (deg <= 360 && deg >= 340) {
         window.localStorage.setItem('prize', 'no1')
         $.get('./fs/mwrite.php?extend=x', function (res) {
             //  console.log(res);
             
         })
         $('.mask').fadeIn("slow")
         $('.mask-mony').on('tap', function (e) {
            $('.mask').html(`<div class="mask-img">
           <form class="submit">
               <h3>请输入您的信息</h3>
               <input name="name" type="text" placeholder="您的姓名">
               <input name="mobile" type="bumber" placeholder="您的手机号">
               <input name="address" type="text" placeholder="您的地址">
               <input type="submit" id="submit">
           </form>
        </div>`)
            $('.submit').on('submit', function (e) {
                e.preventDefault();
                $.ajax({
                    url: './fs/fwrite.php',
                    type: 'get',
                    data: $(this).serialize(),
                    success: function (res) {
                       window.localStorage.removeItem('prize')
                        $('.submit').html('<h1>提交成功</h1>')
                        setTimeout(function () {
                            $('.mask').fadeOut("slow")
                        }, 3000)
                    }
                })
            })
        })

         return 'one'
     }
 }

 //  概率判断
 function randomDeg(i) {
    //  var nub = Math.floor(Math.random() * 10000) + i
      var nub = 5001 + i;
     var plus = Math.floor(Math.random() * 20)
     if (nub === 0) {
         return 0 + plus
     } else if (nub >= 1 && nub <= 2000) {
         return 130 + plus
     } else if (nub > 2000 && nub <= 5000) {
         return 30 + plus
     } else if (nub > 5000 && nub < 10000) {
         return 80 + plus
     }
 }

 // 推出后可以继续领取
 function retry(prize) {
     if (!prize) {
         alert('您已经领取过奖品了哦！')
         return
     }

     $('.mask').fadeIn("slow")
     $('.mask-mony').attr('src', './imgs/' + prize + '.png').on('tap', function () {
        //  alert('这是要跳转页面的操作')
        //  window.localStorage.removeItem('prize')
        if(prize=='no1'){
            $('.mask').html(`<div class="mask-img">
            <form class="submit">
                <h3>请输入您的信息</h3>
                <input name="name" type="text" placeholder="您的姓名">
                <input name="mobile" type="bumber" placeholder="您的手机号">
                <input name="address" type="text" placeholder="您的地址">
                <input type="submit" id="submit">
            </form>
         </div>`)
             $('.submit').on('submit', function (e) {
                 e.preventDefault();
                 $.ajax({
                     url: './fs/fwrite.php',
                     type: 'get',
                     data: $(this).serialize(),
                     success: function (res) {
                        window.localStorage.removeItem('prize')
                         $('.submit').html('<h1>提交成功</h1>')
                         setTimeout(function () {
                             $('.mask').hide()
                         }, 3000)
                     }
                 })
             })
        }else if(prize=='no2'){
        //  alert('这是要跳转页面的操作')
            window.location.href = 'https://crmminisite.verystar.cn/wx_service/self_extract?event_key=9f74a18075b6e44fd73dbf05d503fa3f'
        }else if(prize=='no3'){
            window.location.href = 'https://crmminisite.verystar.cn/wx_service/self_extract?event_key=0022a3e4eec8ff9c15a6eaa19a7f0f86'
            
        }else if(prize=='no4'){
            window.location.href = 'https://crmminisite.verystar.cn/wx_service/self_extract?event_key=42ed0eee8643e9218cdd19c98e149540'
            
        }
     })
 }

 var KinerLottery = new KinerLottery({
     rotateNum: 8, //转盘转动圈数
     body: "#box", //大转盘整体的选择符或zepto对象
     direction: 0, //0为顺时针转动,1为逆时针转动
     disabledHandler: function (key) {
         switch (key) {
             case "noStart":
                 alert("活动尚未开始");
                 break;
             case "completed":
             console.log(window.localStorage.getItem('prize'));
                 retry(window.localStorage.getItem('prize'))
                 break;
         }
     }, //禁止抽奖时回调

     clickCallback: function () {
         var that = this
         //此处访问接口获取奖品
         $.get('./fs/mread.php', function (res) {
             console.log(res.length);
              if (res.length >= 100) {
                 that.goKinerLottery(randomDeg(2));                
                 return
              }
             that.goKinerLottery(randomDeg(0));
             //  randomDeg(0)
         })
     }, //点击抽奖按钮,再次回调中实现访问后台获取抽奖结果,拿到抽奖结果后显示抽奖画面

     KinerLotteryHandler: function (deg) {
         whichAward(deg)
         localStorage.setItem('flang', 'ok')
         document.querySelector('.KinerLotteryBtn').classList.add('completed')
         document.querySelector('.KinerLotteryBtn').classList.remove('start')

     } //抽奖结束回调
 });

 //  判断是否参加过活动

 if (localStorage.getItem('flang')) {
     document.querySelector('.KinerLotteryBtn').classList.add('completed')
     document.querySelector('.KinerLotteryBtn').classList.remove('start')
 };

 // 表单提交
 function isWeiXin() {
    var ua = window.navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        return true;
    } else {
        return false;
    }
}
// 欢迎页
$('.fead-in-click').on('tap',function(){
    if(!isWeiXin()){
        confirm('活动页面需要在微信中打开哦！')
        return
    }
    $('.fead-in').fadeOut("slow")
})






 /** 屏蔽分享 */
 // function onBridgeReady() {
 //     WeixinJSBridge.call('hideOptionMenu');
 //     }


 //     if (typeof WeixinJSBridge == "undefined") {
 //     if (document.addEventListener) {
 //     document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
 //     } else if (document.attachEvent) {
 //     document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
 //     document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
 //     }
 //     } else {
 //     onBridgeReady();
 //     }